package com.kong.controller;

import com.kong.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping(value = "/api/user")
public class UserController {


    @Autowired
    private StringRedisTemplate redisTemplate;

    @PostMapping("/login")
    public String login(HttpServletRequest request, @RequestBody User user) {

        HttpSession session = request.getSession();
//        session.setAttribute("loginUserId", user.getName());
        redisTemplate.opsForValue().set("loginUser:" + user.getName(), session.getId());

        return "登录成功！";

    }

    @RequestMapping(value = "/getUserInfo")
    public String get(long userId) {
        return "查询成功！";
    }
}